/**
 * 全部进件控制器
 */
import $_fn from '~plugins'
export default ['$scope','$rootScope','$location','$ui','http','$state',function($scope,$rootScope,$location,$ui,http,$state) {
    var search = $location.search()
    $scope.state = search.state || 1
    $scope.search = !$_fn.isEmptyObject(search)?search:{state:1}
    $scope.dataList = []
    $scope.isData = false
    //分页参数
    $scope.page = {
        current: search.pageNum ||  1
    }
    //获取数据的入参
    $scope.params = {
        s_id:search.state || 1,
        sIds:''   //后台可能会不一样，暂时写成空，例如:1,2,3,4,5,不明白问后台
    }
    //获取数据的函数
    $scope.getDada = function(page){
        $scope.params.pageNum = page
        http.post('selectOrderList.do',$scope.params,function (data) {
            var _data = data.data
            $scope.page.pageNum =  $scope.page.current
            $scope.page.pageSize = _data.pageSize
            $scope.page.total = _data.total
            if(data.errcode > 0){
                //列表无数据
                if(_data.list.length === 0){
                    $scope.isData = true
                }
                $scope.$apply(function () {
                    $scope.dataList = _data.list
                })
            }
        },function(){
            //报错时
            $scope.isData = true
        })
    }
    $scope.getDada(1)  //初始化数据
    /**
     * 四级权限菜单
     * state = 1                      地址栏所要显示的菜单
     * path = link@、alert@           link(连接)、alert(弹窗) 例:link@application.intoa(跳转到全部进件列表)
     * */
    $scope.operation = function (path) {
        var _path = path.split('@')
        if(_path[0] == 'link'){
            console.log(path)
            $state.go(_path[1],{id:1,ids:2})
        }
        if(_path[0] == 'alert'){
            $ui.modal({content:"<"+_path[1]+"></"+_path[1]+">"})
        }
    }
    //搜索
    $scope.name1 = '88'
    $scope.name2 = '2'
    $scope.name3 = '5'
    $scope.stime = '1998-02-12'
    $scope.otime = '1998-08-12'
    $scope.select = [{name:'以租代购',value:55},{name:'信贷方式',value:88}]
    $scope.popup = {
        opened: true
    }
    $scope.click = function () {
        $scope.stime = new Date('1998-02-27')
        console.log($scope.stime)
    }

    //获取当前路由的四级权限
    var menu = $_fn.getLocal('parentMenu')
    $scope.subMenu = []
    var _subMenu = function (path,_menu) {
        for (var a in _menu) {
            if (_menu[a].children) {
                for (var i in _menu[a].children) {
                    if (_menu[a].children[i].path == path) {
                        $scope.subMenu = _menu[a].children[i].children
                        break
                    } else {
                        _subMenu(path,_menu[a].children[i].children)
                    }
                }
            }
        }
    }
    _subMenu('/application/intoa',menu.children)
}]
